﻿/*!
 * gui-tare JavaScript Library v0.1a
 *
 * Includes JQuery
 * http://jquery.com/
 *
 * Copyright 2012 gui-tare Foundation and other contributors
 * Released under the GNU license
 *
 */

 
 var guiTareNameSpace = {
	
	pushanimation : function(element,anim, action)
	{
		if (element.data('reserved') === undefined) return;
	  if (anim) {

		element.data('reserved')._action = action;
		element.addClass('animated-tiny ' + anim);
	  }
	  else {
		action();
	  }
	},
	
	readCookies : function() {
		var ret = {};
		if (document.cookie)
		{
			var attributes = document.cookie.split(';');
			for(var j=0; j<attributes.length; j++) {
				var entry = attributes[j].split('=');
				if (entry[0].trim() === '') continue;
				ret[entry[0].trim()] = (entry[1] === undefined) ? null : entry[1].trim();
			}
		}
		return ret;
	},
	
	readOptions : function(tag)
	{
		var options = tag.getAttribute('data-options');
		// convert "xxxx:yyy ; aaa;" to { xxxx: yyy, aaa : null}
		var ret = {};
		if (options)
		{
			var attributes = options.split(';');
			for(var j=0; j<attributes.length; j++) {
				var entry = attributes[j].split(':');
				if (entry[0].trim() === '') continue;
				ret[entry[0].trim()] = (entry[1] === undefined) ? null : entry[1].trim();
			}
		}
		return ret;
	},
	
	textTo : function(xml,html)
	{
		$(xml).contents().each(function(index) {
			if (this.nodeType == 3) {
				//this.innerHTML
				var txt = $(this).text();
				$(html).append(txt);
			}
		});
	},
	
	executeChildrensPlugin : function(xml,html)
	{
		
		$(xml).contents().filter(function() {
			if (this.nodeType == 3)	return true;
			if (this.nodeType == 1) {
				var tag = this.tagName.trim().toLowerCase();
				if (tag == 'event') return false;
				return true;
			}
			return false;
		}).each(function(index) {
			if (this.nodeType == 3) {
				//this.innerHTML
				var txt = $(this).text();
				$(html).append(txt);
			} else if (this.nodeType == 1) {
				guiTareNameSpace.executePlugin(this,html);
			}
		});
	},
	
	executePlugin : function(element,html)
	{
		function analyzevent(element,html)
		{
			// bug queryselectorall by firefox! sucker!!
			var balises = $(element).children('event');
			for(var i = 0; i <balises.length; i++)
			{
				var tag = balises[i].tagName.trim().toLowerCase();
				if (tag == 'event')
				{
					var type = balises[i].getAttribute('type');
					if (type)
					{
						var exec = $(balises[i]).text();
						html.setAttribute(type,exec);
						for(var c = 1;c <= 10;c++)
						{
							if (type == "onCustomEvent" + c)
							{
								$(html).on(type, new Function(exec));
								break;
							}
						}
					}
				}
			}
		}

		var tag = element.tagName.trim().toLowerCase();
		if (tag == 'event')
		{
			throw '-> error: contact drak poulpo synpp@hotmail.com';
		/*
			var type = element.getAttribute('type');
			if (type) {
				var exec = $(element).text();
				html.setAttribute(type,exec);
				for(var c = 1;c <= 10;c++)
				{
					if (type == "onCustomEvent" + c)
					{
						
						$(html).on(type, new Function(exec));
						break;
					}
				}
			}
			*/
		}
		else {
			
			guiTareNameSpace.loadPlugin(tag);
			
			
			var newobj = $(window).data('gui').plugins[tag];
			
			if (newobj === undefined)
			{
				console.error('-> Check that the object is located in the folder "plugins /" website?');
				throw '-> not found the <' + tag + '> plugin!';
				//return;
			}
			
			var optionsarray = guiTareNameSpace.readOptions(element);
			var nobj = newobj.makeHTML({ 'xml' : element, 'options' : optionsarray, 'parent' : html });
			if (nobj !== null)
			{
				if (optionsarray['skinnable'] !== undefined)
				{
					if (optionsarray['skinnable'].toLowerCase() === 'false')
					{
						nobj.removeAttribute('data-effect');
					}
				}
			
				var attrs = element.attributes;
				for(var key = 0; key < attrs.length ; key++) {
					if (attrs[key].name.trim().substr(0,2).toLowerCase() == 'on' ) continue;
					else if (attrs[key].name.trim().toLowerCase() == 'style' ) {
						var attr = nobj.getAttribute('style');
						if (attr) attrs[key].value += ';' + attr;
					} else if (attrs[key].name.trim().toLowerCase() == 'class' ) {
						var attr = nobj.getAttribute('class');
						if (attr) attrs[key].value += ';' + attr;
					}
					nobj.setAttribute(attrs[key].name,attrs[key].value);
				}
	
				if (optionsarray['storage'] === 'true')
				{
					var id = nobj.getAttribute('id');
					var v = $gui.storageValue(id);
						
					if (v !== undefined && v !== null) {
						if (nobj.tagName.toLowerCase() === 'input' && nobj.type.toLowerCase() === 'checkbox') nobj.checked = (v === 'true');
						else if (nobj.tagName.toLowerCase() === 'input' && nobj.type.toLowerCase() === 'radio') nobj.checked = (v === 'true');
						else $(nobj).val(v);
					}
				}
				
				nobj.setAttribute('data-type',tag);
				//html.appendChild(nobj);

				

				
				analyzevent(element,nobj);
				
				return nobj;
			}
		
		}
		return null;
	} ,
	
	loadPlugin: function(tag)
	{
		
			var js = 'plugins/' + tag + '/plugin.js';
			var css = 'plugins/' + tag + '/plugin.css';

			//console.info('-> loading of plugin : '+ tag );

			var th = ['themes/default/',''];
			

			
			for (var t = 0; t < th.length;t++)
			{
				for (var m = 0; m < $(window).data('gui').mirrors.length;m++)
				{
					//$("head").append($("<link rel='stylesheet' href='" + $(window).data('gui').mirrors[m] + css + "' type='text/css' />"));
					
					if ($(window).data('gui').plugins[tag] === undefined)
					{
						$.getScript( $(window).data('gui').mirrors[m] + th[t] + js).done(function(script, textStatus) {
						
							$(document).ready(function(){
								$.ajax({
									async: false,
									url: $(window).data('gui').mirrors[m] + th[t] + css ,
									dataType:"text"
									/*,
									success:function(data){
									}*/
								}).done(function(data) {
									$("head").append("<style>" + data + "</style>");
									//loading complete code here
									console.info('plugin loaded : ' + tag + ' ('+ $(window).data('gui').mirrors[m] + th[t]+')' );
									
								}).fail(function() { 
									$(window).data('gui').plugins[tag] = undefined;
								});
		
							});
						
						}).fail(function(jqxhr, settings, exception) {
							$(window).data('gui').plugins[tag] = undefined;
						});  
					}
				}
			}
		
	}


 
 
 } ;
 
// 


(function($) {
        $.fn.guiTare = function() {
          return $gui(this);
        };
})(jQuery);


function $gui(element)
{
	var jqueryvar = (element.__proto__.jquery === undefined)? $(element) : element;

	if(jqueryvar.attr('data-type') === undefined) jqueryvar = jqueryvar.parents('[data-type]');

	if (jqueryvar.length == 0)
	{
		throw "-> Element not include in your gui-tare window !";
		return null;
	}

	var ret = [jqueryvar.get(0)];
	ret.jquery = jqueryvar;

	var type = jqueryvar.attr('data-type').trim().toLowerCase();

	if ($(window).data('gui').plugins[type] === null ) return null;
	if ($(window).data('gui').plugins[type] === undefined ) return null;

	ret.__proto__ = $(window).data('gui').plugins[type];
	
	if (ret.__proto__.show === undefined)
	{
		ret.__proto__.show = function(flag)
		{
			if (flag === true) this.jquery.css('visibility','visible');
			else if (flag === false) this.jquery.css('visibility','hidden');
			else if (flag === undefined) return (this.jquery.css('visibility') === 'visible');
			return this;
		};
	}
	
	ret.__proto__.getMyRoot = function ()
	{
		
		if (this[0].parentElement.tagName.trim().toLowerCase() === 'body')  return this;

		var master = this.jquery.parents('[data-type]');	
		for (var i = 0; i < master.length; i++)
		{
			if (master.get(i).parentElement.tagName.trim().toLowerCase() === 'body') return $gui(master[i]);
		}
		throw "-> Element not include in your project gui-tare!";
		return null;
	};

	ret.__proto__.get = function ()
	{
		return this[0];
	};

	/*
	ret.__proto__.tooltip = function (textorhtml)
	{
		
	};
	*/
	
	ret.__proto__.saveStorage = function()
	{
	
		var optionsarray = guiTareNameSpace.readOptions(this[0]);
		
		if (optionsarray['storage'] === 'true')
		{
			var id = this[0].getAttribute('id');
			var v = null;
				
			if (this[0].tagName.toLowerCase() === 'input' && this[0].type.toLowerCase() === 'checkbox') v = this[0].checked;
			else if (this[0].tagName.toLowerCase() === 'input' && this[0].type.toLowerCase() === 'radio') v = this[0].checked;
			else v = this.value();
				
			$gui.storageValue(id,v);
		}
		return this;
	}
	
	ret.__proto__.addElement = function(stringxml)
	{
		var uixml = $.parseXML( stringxml );
		if (uixml === null || uixml === undefined) return null;
		var ret = guiTareNameSpace.executePlugin(uixml.documentElement,this.get());
		if (ret) return $gui(ret);
		return null;
	}
	return ret;
}

$gui.storageValue = function(name,value)
{
	if (value !== undefined)
	{
		if ($(window).data('gui').storage === null) {
			console.error("-> $gui.storage(applicationname) not called");
		} else if (name === null) {
			console.error("-> name undefined");							
		} else if (name.trim() == "") {
			console.error("-> name undefined");
		} else if (typeof(Storage)!=="undefined" && $(window).data('gui').storagetype === 'local')
		{
			
			localStorage[$(window).data('gui').storage + '_' + name] = value;
		} else if ($(window).data('gui').storagetype === 'cookie')
		{
			var date = new Date();
			date.setTime(date.getTime()+(2000*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
			document.cookie = $(window).data('gui').storage + '_' + name+"=" + value + expires + "; path=/";
		}  else if ($(window).data('gui').storagetype === 'both')
		{
			if (typeof(Storage)!=="undefined" )
			{
				localStorage[$(window).data('gui').storage + '_' + name] = value;
			} else {
				var date = new Date();
				date.setTime(date.getTime()+(2000*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
				document.cookie = $(window).data('gui').storage + '_' + name+"=" + value + expires + "; path=/";
			}
		}
	} else
	{
		var v = null;
		if ($(window).data('gui').storage === null) {
			console.error("-> $gui.storage(applicationname) not called");
		} else if (name === null) {
			console.error("-> name undefined");							
		} else if (name.trim() == "") {
			console.error("-> name undefined");
		} else if ($(window).data('gui').storagetype === 'local')
		{
			if(typeof(Storage)!=="undefined") v = localStorage[$(window).data('gui').storage + '_' + name];
		} else if ($(window).data('gui').storagetype === 'cookie')
		{
				var cookies = guiTareNameSpace.readCookies();
				v = cookies[$(window).data('gui').storage + '_' + name];
		} else if ($(window).data('gui').storagetype === 'both')
		{
			if(typeof(Storage)!=="undefined") v = localStorage[$(window).data('gui').storage + '_' + name];
			else
			{
				var cookies = guiTareNameSpace.readCookies();
				v = cookies[$(window).data('gui').storage + '_' + name];	
			}
		}
		return v;	
	}
}

$gui.version = function()
{
	return '1.0a';
}

$gui.compileToXml = function(form)
{

	function recursive(xml,actual)
	{
		if (actual === null) return null;

		var id = actual.getAttribute('id');
		var type = actual.getAttribute('data-type');
		var system = actual.getAttribute('data-system');

		if (system !== null)
		{
			if (system.trim().toLowerCase() !== '') return null;
		}

		if (type.trim().toLowerCase() == '')
		{
			console.error('-> please, verify than the file gui-tare/ui.xml exist!');
			return null;
		}

		console.info("-> export '" + type + "' to XML format");

		var element = $gui(actual).makeXML(xml);
		if (element)
		{

			var attrs = actual.attributes;
			for(var key = 0; key < attrs.length ; key++) {
				if (attrs[key].name.trim().substr(0,2).toLowerCase() == 'on' ) {
					var event = xml.ownerDocument.createElement("event");
					var code =  xml.ownerDocument.createTextNode("<![CDATA[" + attrs[key].value + "]]>");
					event.appendChild(code);
					event.setAttribute('type' , attrs[key].name.trim());
					element.appendChild(event);
				} else if (attrs[key].name.trim().toLowerCase() == 'data-type' ) continue;
				else if (attrs[key].name.trim().toLowerCase() == 'type' ) continue;
				else if (attrs[key].name.trim().toLowerCase() == 'data-effect' ) continue;

				element.setAttribute(attrs[key].name,attrs[key].value);
			}

			xml.appendChild(element);
		} else
		{
			console.error("-> no can't create '" + type + "' element");
			console.error("-> you can help us to solve this problem : https://code.google.com/p/gui-tare/");
		}

		var child = $(actual).children('[data-type]');
		for (var c = 0; c < child.length; c++)
		{
			 recursive(element,child[c]);
		}
	}



	var xml = $(window).data('gui').reserved_userinterface;
	if (xml === null)
	{
		console.error('-> please, verify than the file gui-tare/ui.xml exist!');
		return null;
	}

	var id = form.getAttribute('id');

	var datatype = form.getAttribute('data-type');
	if (datatype.trim().toLowerCase() == 'window')
	{
		var found = xml.getElementById(id);
		if (found !== null)
		{
			var ecraser = confirm ("this window already exist in ui.xml\ndo you want to erase ?")
			if (ecraser)
			{
				found.parentElement.removeChild(found);
			}
			else return null;
		}
	}

	recursive(xml.firstChild,form);

	console.info(xml);
}

// type = local | cookie | both
$gui.storage = function(name,type)
{
	if ($(window).data('gui').storage === null)	$(window).data('gui').storage = name;
	if ($(window).data('gui').storagetype === null)	$(window).data('gui').storagetype = type.toLowerCase();
}

$gui.createGui = function(id,options)
{
	options = options || {};
	
	if (!$(window).data('gui').reserved_userinterface) return null;
	if (typeof(id) !== 'string' )
	{
		console.error('-> id parameter is not valid');
		return null;
	}
	
	var xmlfen = $(window).data('gui').reserved_userinterface.querySelector("[id=" + id + "]");

	if (!xmlfen)
	{
		console.error("-> '" + id + "' don't exist!");
		return null;
	}

	
	var optionsfen = guiTareNameSpace.readOptions(xmlfen);

	if (xmlfen.tagName.toLowerCase() === 'window')
	{
		if (optionsfen.unique === 'true')
		{
			var found = $('body').find('div[id=' + id + ']');
			if (found.length != 0) return $gui(found.get(0));
		}

		// options
		if (options.center === undefined) options.center = (optionsfen.center !== undefined) ? optionsfen.center : 'none';
		options.x = (options.x === undefined) ? null : options.x;
		options.y = (options.y === undefined) ? null : options.y;
		
	    
		if (options.alwaysinforeground === undefined) options.alwaysinforeground = (optionsfen.alwaysinforeground !== undefined) ? optionsfen.alwaysinforeground : false;
		
        options.modal = (optionsfen.modal === undefined) ? false : optionsfen.modal;
		
		// transform to $gui object
		//  var gfen = $gui(fenetre);

		// create all elements of windows
		
		var fenetre = guiTareNameSpace.executePlugin(xmlfen,$('body').get(0));

		
		var gfen = $gui(fenetre);

		if (options.x) $(fenetre).css('left', options.x + 'px');
		if (options.y) $(fenetre).css('top', options.y + 'px');
		
		
		
		$(fenetre).find('[data-type]').each(function(index)
		{
			var optionsplugin = guiTareNameSpace.readOptions(this);

			if (optionsplugin['autosize'] !== undefined)
			{
				if (optionsplugin['autosize'].toLowerCase() === "width")
				{
					var formule = '100%';
				
					formule = formule + ' - ' + $(this).css('border-right-width') + ' - ' + $(this).css('margin-right');
					
					formule = formule + ' - ' + $(this).position().left + 'px';
					formule = 'calc(' + formule + ')';

					if ($(this).css('-moz-user-select') !== undefined)	formule = "-moz-"+formule;
					else if ($(this).css('-webkit-user-select') !== undefined)	formule = "-webkit-"+formule;
					else if ($(this).css('-khtml-user-select') !== undefined)	formule = "-khtml-"+formule;
					else if ($(this).css('-o-user-select') !== undefined)	formule = "-o-"+formule;
					else if ($(this).css('-ms-user-select') !== undefined)	formule = "-ms-"+formule;

					$(this).css('width', formule);
				}
			}
		});
		

		if (options.center === 'xy')
		{
			$(fenetre).css({
				'top':Math.abs((($(document).height() - $(fenetre).outerHeight()) / 2)) + 'px',
				'left':Math.abs((($(document).width() - $(fenetre).outerWidth()) / 2)) + 'px'
			});
		}
		else if (options.center === 'y') $(fenetre).css('top',Math.abs((($(document).height() - $(fenetre).outerHeight()) / 2)) + 'px');
		else if (options.center === 'x') $(fenetre).css('left',Math.abs((($(document).width() - $(fenetre).outerWidth()) / 2)) + 'px');

		
		if (options.alwaysinforeground === 'true') gfen.alwaysInForeground();

		if (options.modal === 'true') 
		{

			var modal = document.createElement("div");
			$(modal).css({
				'height': $(document).height() + 'px',
				'width': $(document).width() + 'px'
			})
			$(modal).attr('id','modal-'+$(fenetre).data('reserved').guid).addClass('submodal');
			$('body').append(modal);
			modal.setAttribute('data-effect','modal');
			$(fenetre).addClass('modal');
		}
		
		
		
		var onload = fenetre.getAttribute("onload");
		if (onload) $(fenetre).on("onload", new Function(onload));

		$(fenetre).trigger("onload");	;

		/*
		$(fenetre).find('[data-type]').each(function(index) {
			$(this).trigger("onload");	;
		});
		*/
		//$(fenetre).trigger("onload");

		guiTareNameSpace.pushanimation($(fenetre),$(window).data('gui').reserved_openanimationname,function(e) {
				e.data('reserved').state = (e.data('reserved').state & 0xffff0000) | $gui.window.SHOWN | $gui.window.NORMAL;
			}
		);

		return gfen;
	} else if (xmlfen.tagName.toLowerCase() === 'hud')
	{
		var hud = guiTareNameSpace.executePlugin(xmlfen,$('body').get(0));
		
		$(hud).find('[data-type]').each(function(index)
		{
			var optionsplugin = guiTareNameSpace.readOptions(this);

			if (optionsplugin['autosize'] !== undefined)
			{
				if (optionsplugin['autosize'].toLowerCase() === "width")
				{
					var formule = '100%';
					
					formule = formule + ' - ' + $(this).css('border-right-width') + ' - ' + $(this).css('margin-right');
					
					formule = formule + ' - ' + $(this).position().left + 'px';
					formule = 'calc(' + formule + ')';

					if ($(this).css('-moz-user-select') !== undefined)	formule = "-moz-"+formule;
					else if ($(this).css('-webkit-user-select') !== undefined)	formule = "-webkit-"+formule;
					else if ($(this).css('-khtml-user-select') !== undefined)	formule = "-khtml-"+formule;
					else if ($(this).css('-o-user-select') !== undefined)	formule = "-o-"+formule;
					else if ($(this).css('-ms-user-select') !== undefined)	formule = "-ms-"+formule;

					$(this).css({'box-sizing': 'border-box', 'width': formule});
				}
			}
		});

		
		
		var ghud = $gui(hud);
		return ghud;
	}
};

 /******************** initialisation gui-tare
 *
 *
 *
 *
 *
 *
 *
 */


 (function (w) {

	function loadplugins(xml)
	{
		$(window).data('gui').reserved_userinterface = xml;
		console.info('-> starting "autoloading" option...');
		var gui = xml.querySelectorAll("gui>*");
		if (gui.length == 0)
		{
			console.error("-> ui.xml empty");
		}
		else
		{
			for (var p = 0; p < gui.length; p++)
			{			
				var options = guiTareNameSpace.readOptions(gui[p]);
				if (options['autoloading'] !== undefined && options['autoloading'] !== 'false')
				{
					var id = gui[p].getAttribute('id');
					var temps = parseInt(options['autoloading']);
					/* don't work
					$(document).delay((isNaN(temps)) ? 1500 : temps).queue(function() {
					$gui.createWindow(id);
					$(this).dequeue();
     			});
					*/
					setTimeout(function(paramid) {$gui.createGui(paramid); },(isNaN(temps)) ? 1500 : temps ,id);
				}
			}
		}
	}


	function extractUrlParams(){
		var _GET = {};
		var re = new RegExp('gui.js\?.+');
		var scripts  = document.getElementsByTagName('script');

		for(var i = 0; i < scripts.length; i++)
		{
			var src = scripts[i].getAttribute('src');
			if(src != null && re.test(src))
			{
				for(var i,a,m,n,o,v,p=src.split(/[?&]/),l=p.length,k=1;k<l;k++)
				{
					if( (m=p[k].match(/(.*?)(\..*?|\[.*?\])?=([^#]*)/))&&m.length==4)
					{
						n= decodeURI(m[1]).toLowerCase(), o=_GET,v = decodeURI(m[3]);
						if (m[2])
						{
							for(a=decodeURI(m[2]).replace(/\[\s*\]/g,"[-1]").split(/[\.\[\]]/),i=0;i<a.length;i++)
							{
								o= o[n] ? o[n] : o[n]=(parseInt(a[i]) == a[i])? [] : {}, n=a[i].replace(/^["\'](.*)["\']$/,"$1");
								n!='-1'?o[n]=v:o[o.length]=v;
							}
						} else
						{
							o[n] = v;
						}
					}
				}
			}
		}
		return _GET;
	}


	/*
	var t = location.search.substring(1).split('&');

	for (var i=0; i<t.length; i++){
		var x = t[ i ].split('=');
		f[x[0]]=x[1];
	}
	*/



  console.info('-> Gui-tare version ' + $gui.version() + ' copyright 2012 by dark poulpo');
  console.info('-> consult https://darkpoulpo13@code.google.com/p/gui-tare/ to add yours contributions');
	//console.info('-> or go to https://github.com/darkpoulpo/Gui-tare/graphs to add yours contributions');

  console.info('-> good morning vietnam!')

  console.info('-> searching any libraries... (jQuery, ...)');
  if (window.jQuery === undefined)
  {
    alert('Gui-tare : Houston, We\'ve Got a Problem! consult your console.');
    throw " -> please, insert <script src='http://code.jquery.com/jquery-git.js'></script> in first to header html";
    throw " -> or <script src='jquery-git.js'></script> in first to header html";
  }

  console.info('-> jQuery loaded :-) (' + jQuery(document).jquery + ')');
  console.info('-> Testing jQuery compatibility...');
  
  if (typeof(jQuery.getScript) === 'undefined')
  {
    alert('Gui-tare : Houston, We\'ve Got a Problem! consult your console.');
    throw " -> the jQuery version is too old, please update it";
  }
  
  console.info('-> jQuery : synchrone mode : ON');
  
   $.ajaxSetup({async:false});

  console.info('-> assign parameters and functions');

	$(window).data('gui', {
		zindex : 2012,
		currentdraganddrop : null,
		reserved_userconfig : null,
		reserved_maximizeanimationname : null,
		reserved_unmaximizeanimationname : null,
		reserved_openanimationname : null,
		reserved_closeanimationname : null,
		reserved_showanimationname : null,
		reserved_hideanimationname : null,
		reserved_minimizeanimationname : null,
		reserved_unminimizeanimationname : null,
		reserved_notificationanimationname : null,
		reserved_titlechangeanimationname : null,
		plugins : {},
		mirrors : [],
		storage : null,
		storagetype : null
    });

   
	console.info('-> establishment of mirror sites');
	var local = extractUrlParams();

	/*
	if (local['toolkit'] === 'true') {
		console.info('-> toolkit version used');
		$(window).data('gui').mirrors.push('http://gui-tare.googlecode.com/git/');
		if (local['gui-path'] !== undefined) $(window).data('gui').mirrors.push(local['gui-path']);
		else $(window).data('gui').mirrors.push('gui-tare/');
	} else if (local['nightly'] === 'true') {
		console.info('-> nightly version used');
		$(window).data('gui').mirrors.push('http://gui-tare.googlecode.com/git/');
	}
	else {
		console.info('-> normal version used');
		if (local['gui-path'] !== undefined) $(window).data('gui').mirrors.push(local['gui-path']);
		else $(window).data('gui').mirrors.push('gui-tare/');
	}
*/

	if (local['gui-path'] !== undefined) $(window).data('gui').mirrors.push(local['gui-path']);
	else $(window).data('gui').mirrors.push('gui-tare/');
	$(window).data('gui').mirrors.push('http://gui-tare.googlecode.com/git/');
	
	
    //console.info('-> assign events');

    console.info('-> loading gui effect...');

    $(window).data('gui').reserved_openanimationname = 'bounceIn';
    $(window).data('gui').reserved_showanimationname = 'fadeIn';
    $(window).data('gui').reserved_hideanimationname = 'fadeOut';
    $(window).data('gui').reserved_closeanimationname = 'hinge'; //bounceOut
    $(window).data('gui').reserved_unmaximizeanimationname = 'flipOutX';
    $(window).data('gui').reserved_maximizeanimationname = 'fadeOut';
    $(window).data('gui').reserved_minimizeanimationname = 'fadeOut';
    $(window).data('gui').reserved_unminimizeanimationname = 'fadeOut';
    $(window).data('gui').reserved_notificationanimationname = 'tada';
    $(window).data('gui').reserved_titlechangeanimationname = 'fadeOutDown';

	
	var files = ['gui.css','themes/default/skin.css','animate.mini.css'];
	for (var f = 0; f < files.length;f++)
	{
		for (var m = 0; m < $(window).data('gui').mirrors.length;m++)
		{	
		
			var bool = false;
			$.ajax({
				async: false,
				url: $(window).data('gui').mirrors[m] + files[f] ,
				dataType:"text"
			}).done(function(data) {
			
				//$("head").append("<style>" + data + "</style>");
				$("head").append($("<link rel='stylesheet' href='" + $(window).data('gui').mirrors[m] + files[f] + "'/>"));
				
				//loading complete code here
				console.info('css loaded : ' + $(window).data('gui').mirrors[m] + files[f] );
				bool = true;
			}).fail(function() { 
				bool = false;
			});
			if (bool) break;
		}
	}
    //document.body.style.overflow = 'hidden';

    console.info('-> loading the user interface...');

	if (local['toolkit'] === 'true') {
		if(typeof(Storage)!=="undefined")
		{
			if (localStorage.uixml)
			{
				var uixml = $.parseXML( localStorage.uixml );
				if (uixml === null || uixml === undefined)
				{
					alert('Gui-tare : Houston, We\'ve Got a Problem! consult your console.');
					console.error("-> argh! we've got an error with the ui.xml, please click on save button.");
					$(window).data('gui').reserved_userinterface = null;
					return;
				}

				loadplugins(uixml);
				return;
			}
		}
	}

   	$.ajax( {type: "GET",url: 'gui-tare/ui.xml',dataType: "xml",success: loadplugins,
      error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert('Gui-tare : Houston, We\'ve Got a Problem! consult your console.');
        console.error("-> argh! we've got an error with the gui-tare/ui.xml");
        $(window).data('gui').reserved_userinterface = null;
      }
   	});
})(window);








